package com.wcl.demo.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;

import com.wcl.demo.R;
import com.wcl.demo.view.Titanic;
import com.wcl.demo.view.TitanicTextView;
import com.wcl.demo.view.Typefaces;

/**
 * Created by dllo on 15/11/17.
 */
public class ProgressUtils {
    private static ProgressUtils progressUtils;
    private static ProgressDialog progressDialog;

    public static ProgressUtils getInstance() {
        if (progressUtils == null) {
            progressUtils = new ProgressUtils();
        }
        return progressUtils;
    }

    /**
     * 显示ProgressDialog
     *
     * @param context
     */
    public static void showProgress(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.activity_loading, null);

        TitanicTextView titanicTextView = (TitanicTextView) view.findViewById(R.id.titanic_tv);
        titanicTextView.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Satisfy-Regular.ttf"));
        Titanic.start(titanicTextView);
        progressDialog = new ProgressDialog(context);
        //  progressDialog.setTitle("请稍等");
        //  progressDialog.setMessage("数据加载中..");
        //设置进度条是否可以按退回键取消
        progressDialog.setCancelable(true);
        //设置点击进度对话框外的区域对话框不消失
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();
        progressDialog.setContentView(view);
    }

    /**
     * 隐藏ProgressDialog
     */
    public static void dismissProgress() {
        progressDialog.dismiss();
        Titanic.cancel();
    }
}
